
#include <mpi.h>
#include <unistd.h>
#include <ctime>
#include "common.h"
#include <cstdio>
#include <list>


int main( int argc, char **argv )
{    

  MPI_Init(&argc, &argv);
  timespec a, b;
  a.tv_sec=0;
  a.tv_nsec = 20000;
  std::list<double> t;
  int rank ;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);


  for(int i=0 ;i<100; i++)
    {
      double dd=read_timer();
      MPI_Barrier(MPI_COMM_WORLD);
      dd=read_timer()-dd;
      if(i>15)
	t.push_back(dd);
      nanosleep(&a, &b);
      if(i%20==0) printf(".");
    }
  
  char buf[12];
  sprintf(buf, "btime%2d", rank);
  FILE* out = fopen(buf, "w");
  int i=0;
  std::list<double>::iterator it;
  for(it=t.begin(); it!= t.end(); ++it, ++i)
     fprintf(out, "%d %e\n", i, *it);
  fclose(out);

  MPI_Finalize();
  return 0;
}
